@extends('layouts.admin.application')

@section('content')
    <div class="main-content">
        <div class="col-xs-12">
            <div class="breadcrumbs" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li><i class="icon-home home-icon"></i><a href="#">首页</a></li>
                    <li>物流管理</li>
                </ul>
            </div>

            @include('layouts.partials._flash')

            <div class="table-responsive">
                <div id="sample-table-2_wrapper" class="dataTables_wrapper" role="grid">
                    <div class="row">
                        <div class="col-sm-2">
                            <div id="sample-table-2_length" class="dataTables_length">
                                <a href="{{ route('shop.express.create') }}"
                                   class="btn btn-sm btn-primary">新增</a>
                            </div>
                        </div>
                    </div>
                    <table id="sample-table-2"
                           class="table table-striped table-bordered table-hover dataTable del-table"
                           aria-describedby="sample-table-2_info">
                        <thead>
                        <tr role="row">
                            <th>编号</th>
                            <th>物流名称</th>
                            <th>物流地址</th>
                            <th>配送方式描述</th>
                            <th>运费 / 满额包邮</th>
                            <th>是否可用</th>
                            <th>排序</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($expresses as $express)
                            <tr class="odd" data-id="{{$express->id}}">
                                <td>{{$express->id}}</td>
                                <td>{{$express->name}}</td>
                                <td>
                                    <a href="{{$express->url}}" target="_blank">{{$express->url}}</a>
                                </td>
                                <td>{{$express->description}}</td>
                                <td>
                                    {{$express->shipping_money}}元 / {{$express->shipping_free}}元
                                </td>
                                <td>
                                    {!! is_something($express,'is_enable') !!}
                                </td>
                                <td>
                                    <input type="text" class="ace sort_order" value="{{$express->sort_order}}"
                                           style="width: 40px;">
                                </td>
                                <td>
                                    <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                        <a class="green" href="{{route('shop.express.edit', $express->id)}}"><i
                                                    class="icon-pencil bigger-130"></i></a>
                                        <a class="red delete_one" href="javascript:;">
                                            <i class="icon-trash bigger-130"></i></a>
                                    </div>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                    <div class="row">
                        <div class="col-sm-6">共 {{$expresses->total()}} 条记录</div>
                        <div class="col-sm-6">
                            <div class="dataTables_paginate paging_bootstrap">
                                <ul class="pagination">
                                    {{ $expresses->appends(Request::all())->links() }}
                                </ul>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script>
        $(function () {
            //ajax删除单条
            $('.delete_one').click(function () {
                var id = $(this).parents('tr').data('id');
                var _this = $(this);
                $.ajax({
                    type: 'DELETE',
                    url: '/admin/shop/express/' + id,
                    data:id,
                    success:function(){
                        _this.parents('tr').fadeOut(400);
                    }
                })
            });

            //ajax排序
            $('.sort_order').change(function () {
                var info = {
                    id: $(this).parents('tr').data('id'),
                    sort_order: $(this).val()
                };

                $.ajax({
                    type: 'PATCH',
                    url: '{{route('shop.express.sort_order')}}',
                    data: info,
                    success: function () {
                        window.location.reload();
                    }
                })
            });

            //改变属性
            $('.change_attr').click(function () {
                var _this = $(this);
                var data = {
                    id: $(this).parents('tr').data('id'),
                    attr: $(this).attr('data-attr')
                };

                $.ajax({
                    type: 'PATCH',
                    url: '{{route('shop.express.change_attr')}}',
                    data: data,
                    success: function () {
                        _this.toggleClass('icon-ok icon-ban-circle');
                    }
                })
            })
        })
    </script>
@endsection

